package com.noble.meether;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;

import com.noble.glamour.module.logic.application.App;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.logic.baseui.LoadingDialog;
import com.noble.glamour.module.logic.request.RequestComplete;
import com.noble.glamour.module.util.UIShow;
import com.noble.glamour.ui.discover.task.UserAuthDialog;
import com.noble.library.camera.ImgSelectUtil;
import com.noble.library.camera.dialog.ImgSelectDialog;
import com.noble.library.log.PToast;
import com.noble.library.permission.PermissionUtil;
import com.noble.library.permission.callback.PermissionListener;
import com.noble.meether.chat.ui.system.SysMessAct;
import com.noble.meether.fragment.start.dialog.PayShareDialog;
import com.noble.meether.logic.third.share.dialog.ShareDialog;
import com.noble.meether.mail.ui.friend.MyFriendsAct;
import com.noble.meether.mail.ui.friend.request.MyFriendRequestAct;
import com.noble.meether.mail.ui.stranger.ChatStrangerAct;
import com.noble.meether.pay.type.PayTypeDialog;
import com.noble.meether.ui.apply.ApplyAccountAct;
import com.noble.meether.ui.apply.ApplyAct;
import com.noble.meether.ui.certify.SexAuthAct;
import com.noble.meether.ui.certify.dialog.SexAuthFailDlg;
import com.noble.meether.ui.dialog.MsgTipDialog;
import com.noble.meether.ui.diamond.MyDiamondsAct;
import com.noble.meether.ui.diamond.detail.DiamondDetailAct;
import com.noble.meether.ui.image.PhotoDisplayAct;
import com.noble.meether.ui.invite.InviteAct;
import com.noble.meether.ui.invite.detail.InviteDetailAct;
import com.noble.meether.ui.invite.exchange.InviteExchangeAct;
import com.noble.meether.ui.invite.rule.InviteRuleAct;
import com.noble.meether.ui.point.MyPointAct;
import com.noble.meether.ui.record.RecordVideoAct;
import com.noble.meether.ui.reg.mobile.RegMobileDlg;
import com.noble.meether.ui.setting.OffNetDescribeAct;
import com.noble.meether.ui.setting.SettingAct;
import com.noble.meether.ui.setting.SuggestAct;
import com.noble.meether.ui.user.UserEditInfoAct;
import com.noble.meether.ui.vip.MyVipAct;
import com.noble.meether.ui.wallet.MyWalletAct;
import com.noble.meether.ui.wallet.detail.WalletDetailAct;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 遇见Ta项目：相关页面跳转
 */
public class MeetUIShow extends UIShow {

    /**
     * 全局信息提示弹框
     */
    public static void showMsgTipDlg(final FragmentActivity context, String content, MsgTipDialog.OnDialogClickListener listener) {
        showMsgTipDlg(context, content, false, listener);
    }

    /**
     * 全局信息提示弹框
     */
    public static void showMsgTipDlg(final FragmentActivity context, String content, boolean isSingle, MsgTipDialog.OnDialogClickListener listener) {
        MsgTipDialog dialog = new MsgTipDialog(content, listener);
        dialog.isSingle(isSingle);
        dialog.showDialog(context);
    }

    /**
     * 手机登录弹框
     */
    public static void showRegMobileDlg(FragmentActivity activity) {
        RegMobileDlg regMobileDlg = new RegMobileDlg();
        regMobileDlg.showDialog(activity);
    }

    /**
     * 打开录制视频页
     */
    public static void showRecordVideoAct(final FragmentActivity context, final int requestCode) {
        PermissionUtil.checkAVPermission(context, new PermissionListener() {
            @Override
            public void success() {
                context.startActivityForResult(new Intent(context, RecordVideoAct.class), requestCode);
            }

            @Override
            public void fail() {
                PToast.showShort("未检测到音视频权限");
            }
        });
    }

    /**
     * 相机选择弹框
     */
    public static void showImgSelectDialog(FragmentActivity activity, ImgSelectUtil.OnChooseCompleteListener listener) {
        ImgSelectDialog imgSelectDialog = new ImgSelectDialog();
        imgSelectDialog.setParam(activity, listener);
        imgSelectDialog.showDialog(activity);
    }

    /**
     * 查看大图界面 url
     */
    public static void showPhotoOfBigImg(FragmentActivity activity, String url) {
        ArrayList<String> pics = new ArrayList<>();
        pics.add(url);
        showPhotoDisplayAct(activity, pics, 0, PhotoDisplayAct.DISPLAY_TYPE_BIG_IMG);
    }

    /**
     * 查看大图界面
     *
     * @param list     Serializable 图片的数据链表对象 （看大图的 传List<String>链表）
     * @param position 选中的 图片 position
     * @param type     需要界面显示的类型
     *                 PhotoDisplayAct.DISPLAY_TYPE_USER; //看自己相册
     *                 PhotoDisplayAct.DISPLAY_TYPE_OTHER; //看别人相册
     *                 PhotoDisplayAct.DISPLAY_TYPE_BIG_IMG; //看大图
     */
    private static void showPhotoDisplayAct(FragmentActivity activity, Serializable list, int position, int type) {
        if (list == null || ((List<String>) list).size() == 0) {
            PToast.showShort("没有图片数据");
            return;
        }
        Intent intent = new Intent(activity, PhotoDisplayAct.class);
        intent.putExtra("list", list);
        intent.putExtra("position", position);
        intent.putExtra("type", type);
        activity.startActivity(intent);
    }

    /**
     * 断网提示页面
     */
    public static void showOffNetDesAct(Context context) {
        Intent intent = new Intent(context, OffNetDescribeAct.class);
        context.startActivity(intent);
    }

    /**
     * 打开设置页
     */
    public static void showUserSetAct(final Activity context, final int resultCode) {
        context.startActivityForResult(new Intent(context, SettingAct.class), resultCode);
    }

    /**
     * 打开意见反馈页面
     */
    public static void showSuggestAct(Context context) {
        context.startActivity(new Intent(context, SuggestAct.class));
    }

    /**
     * 打开我的钱包页面
     */
    public static void showMyWalletAct(Context context) {
        context.startActivity(new Intent(context, MyWalletAct.class));
    }

    /**
     * 打开个人信息查看编辑页
     */
    public static void showUserEditInfoAct(Context context) {
        context.startActivity(new Intent(context, UserEditInfoAct.class));
    }

    /**
     * 打开我的好友界面
     */
    public static void showMyFriendsAct(Context context) {
        Intent intent = new Intent(context, MyFriendsAct.class);
        context.startActivity(intent);
    }

    /**
     * 打开好友申请界面
     */
    public static void showMyFriendRequestAct(Context context) {
        Intent intent = new Intent(context, MyFriendRequestAct.class);
        context.startActivity(intent);
    }

    /**
     * 打开陌生人消息
     */
    public static void showChatStrangerAct(Context context) {
        Intent intent = new Intent(context, ChatStrangerAct.class);
        context.startActivity(intent);
    }

    /**
     * 打开我的钻石页面
     */
    public static void showMyDiamondsAct(Context context) {
        context.startActivity(new Intent(context, MyDiamondsAct.class));
    }

    /**
     * 打开钻石明细
     */
    public static void showDiamondDetailAct(Context context) {
        context.startActivity(new Intent(context, DiamondDetailAct.class));
    }

    /**
     * 打开收益明细
     */
    public static void showWalletDetailAct(Context context) {
        context.startActivity(new Intent(context, WalletDetailAct.class));
    }

    /**
     * 打开我的VIP
     */
    public static void showMyVipAct(Context context) {
        context.startActivity(new Intent(context, MyVipAct.class));
    }

    /**
     * 打开我的指标
     */
    public static void showMyPointAct(Context context) {
        context.startActivity(new Intent(context, MyPointAct.class));
    }

    /**
     * 邀请赚钱
     */
    public static void showInviteAct(Context context) {
        context.startActivity(new Intent(context, InviteAct.class));
    }

    /**
     * 邀请规则
     */
    public static void showInviteRuleAct(Context context) {
        context.startActivity(new Intent(context, InviteRuleAct.class));
    }

    /**
     * 邀请明细
     */
    public static void showInviteDetailAct(Context context) {
        context.startActivity(new Intent(context, InviteDetailAct.class));
    }

    /**
     * 邀请明细
     */
    public static void showInviteExchangeAct(Context context) {
        context.startActivity(new Intent(context, InviteExchangeAct.class));
    }

    /**
     * 提现
     *
     * @param channel 提现类型 -1: 陪聊收益  -2: 邀请奖励
     */
    public static void showApplyAct(Context context, int channel) {
        Intent intent = new Intent(context, ApplyAct.class);
        intent.putExtra("channel", channel);
        context.startActivity(intent);
    }

    /**
     * 添加账户
     */
    public static void showApplyAccountAct(Context context) {
        context.startActivity(new Intent(context, ApplyAccountAct.class));
    }

    /**
     * 女性： 性别认证
     */
    public static void showSexAuthAct(FragmentActivity context) {
        context.startActivity(new Intent(context, SexAuthAct.class));
    }

    /**
     * 认证失败提示弹框
     */
    public static void showSexAuthFailDlg(FragmentActivity activity, String content) {
        SexAuthFailDlg dialog = new SexAuthFailDlg(content);
        dialog.showDialog(activity);
    }

    // ====================== 消息相关 ==================

    /**
     * 官方公告消息页面
     */
    public static void showSysMessActivity(Context context) {
        context.startActivity(new Intent(context, SysMessAct.class));
    }

    /**
     * 打开资料认证提示弹框
     */
    public static void showUserAuthDlg(FragmentActivity context) {
        UserAuthDialog dialog = new UserAuthDialog();
        dialog.showDialog(context);
    }

    /**
     * 打开支付方式选择
     *
     * @param productType 商品类型： 钻石 = 1； VIP = 2
     * @param productCode 商品Id
     * @param subject     title标题
     */
    public static void showPayTypeDlg(FragmentActivity context, final int productType, final int productCode, final String subject) {
        PayTypeDialog payTypeDialog = new PayTypeDialog((parent, view, position, id) -> pay(position + 1, productType, productCode, subject));
        payTypeDialog.showDialog(context);
    }

    public static void pay(int position, int productType, int productCode, String subject) {
        if (productCode <= 0) {
            PToast.showShort("获取商品信息失败，请稍后重试");
            return;
        }
        ModuleMgr.getCommonMgr().reqPayAdd(position, productType, productCode, subject, null);
    }

    /**
     * 展示分享弹框
     */
    public static void showShareDialog(FragmentActivity activity) {
        ShareDialog shareDialog = new ShareDialog();
        shareDialog.showDialog(activity);
    }

    /**
     * 展示充值分享提示弹框
     */
    public static void showPayShareDialog(FragmentActivity activity) {
        PayShareDialog dialog = new PayShareDialog();
        dialog.showDialog(activity);
    }

    /**
     * 添加好友弹框
     */
    public static void showAddFriendDlg(final long tuid, String name, final RequestComplete complete) {
        String content = TextUtils.isEmpty(name) ? "确定添加该用户为好友吗?" :
                "确定添加 " + name + " 为好友吗?";
        showMsgTipDlg((FragmentActivity) App.activity,
                content, new MsgTipDialog.OnDialogClickListener() {
                    @Override
                    public void onSubmit() {
                        LoadingDialog.show((FragmentActivity) App.activity, "请稍后...");
                        ModuleMgr.getCommonMgr().setAddFriends(tuid, complete);
                    }

                    @Override
                    public void onCancel() {
                    }
                });
    }
}
